/////////////////////////////////////////////////////////////////////////////
// 2023 -
//open source under Apache License Version 2.0
/////////////////////////////////////////////////////////////////////////////
//  Modifications by Kumo Inc.
// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <kmhdfs/client/raw_erasure_coder_factory.h>
#include <kmhdfs/client/native_rs_raw_encoder.h>
#include <kmhdfs/client/native_rs_raw_decoder.h>
#include <turbo/log/logging.h>
#include <turbo/strings/str_format.h>
#include <turbo/log/logging.h>

namespace Hdfs {
namespace Internal {

bool RawErasureCoderFactory::buildSupportsIsal() {
#ifdef HADOOP_ISAL_LIBRARY
    return true;
#else
    return false;
#endif
}

std::shared_ptr<RawErasureEncoder> RawErasureCoderFactory::createEncoder(ErasureCoderOptions & coderOptions) {
    if (buildSupportsIsal()) {
	VKLOG(300)<<turbo::str_format( "support isa-l");
        return std::shared_ptr<NativeRSRawEncoder>(new NativeRSRawEncoder(coderOptions));
    } else {
	VKLOG(300)<<turbo::str_format( "not support isa-l");
        return std::shared_ptr<RawErasureEncoder>(new RawErasureEncoder(coderOptions));
    }
}

std::shared_ptr<RawErasureDecoder> RawErasureCoderFactory::createDecoder(ErasureCoderOptions & coderOptions) {
    if (buildSupportsIsal()) {
	VKLOG(300)<<turbo::str_format( "support isa-l");
        return std::shared_ptr<NativeRSRawDecoder>(new NativeRSRawDecoder(coderOptions));
    } else {
	VKLOG(300)<<turbo::str_format( "not support isa-l");
        return std::shared_ptr<RawErasureDecoder>(new RawErasureDecoder(coderOptions));
    }
}

}
}